<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script>
$(function(){
	$(".ajax_provider").autocomplete("<?=url('Purchase::Order/Provider')?>").result(function(event, data, formatted){
		if (data[0])
		{
			var container = $(this).parent().parent();
			container.find("input.actual_provider_id").val(data['id']);
		}
	});
	$("#add_save").click(function(){
		var wrong_flag = false;
		$(".actual_quantity").each(function(){
			if ($(this).val())
			{
				if (parseInt($(this).val()) > parseInt($(this).prev().val()))
				{
					alert('产品编号' + $(this).parent().parent().children(":first").text() + '，实际数不能大于预计数！');
					wrong_flag = true;
				}
			}
		});
        $(".actual_price").each(function(){
			if ($(this).val())
			{
				if (parseFloat($(this).val()) > parseFloat($(this).prev().val()))
				{
					if(!confirm('产品编号' + $(this).parent().parent().children(":first" ).text() + '，实际价不能大于预计价！' ))
					{
						wrong_flag = true;
					}
				}
			}
		});
		if (wrong_flag)
		{
			return false;
		}
	});
	$("#note").click(function(){
        var numbers ="";
		$(".number").each(function(){
			if($(this).val())
			{
				numbers += $(this).val()+",";
			}
		});
		window.open("<?=url('Datacenter::Purchase/Stockanalysis')?>&product_numbers=" + numbers + "&is_search=1&warehouse_id=1&backorder=on");
	});
});
</script>
<fieldset>
<table class="form_table">
	<tr>
		<th>采购单号</th>
		<td><?=$purchase_order['number']?></td>
		<th>采购日期</th>
		<td><?=$purchase_order['purchase_time']?></td>
	</tr>
	<tr>
		<th>采购人员</th>
		<td><?=$purchase_order['purchase_user_name']?></td>
		<th>结款类型</th>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_payment_type', 'value', $purchase_order['payment_type'], 'name')?></td>
	</tr>
	<tr>
		<th>所属仓库</th>
		<td><?=$purchase_order['warehouse_name']?></td>
	</tr>
	<tr>
		<th>备注</th>
		<td colspan="3"><textarea rows="3" cols="60" disabled="disabled"><?=$purchase_order['notes']?></textarea></td>
	</tr>
</table>
</fieldset>
<form method="post" action="<?=url('Purchase::Order/ActualEditSave')?>" id="actual_edit_form">
<input type="hidden" name="id" value="<?=$purchase_order['id']?>" />
<table width="100%" class="list_table" >
	<tr>
		<th width="50">产品编号</th>
		<th>产品名称</th>
		<th width="50">警告库存</th>
		<th width="50">安全库存</th>
		<th width="40">库存</th>
		<th width="40">待发</th>
		<th width="50">预计数</th>
		<th width="50">预计价</th>
		<th width="150">预计供应商</th>
		<th width="50">实际数</th>
		<th width="50">实际价</th>
		<th width="250">实际供应商</th>
		<th>备注</th>
	</tr>
	<?foreach ($item as $i):?>
	<tr>
		<td><input type="hidden" class="number" value="<?=$i['product_number']?>" /><?=$i['product_number']?></td>
		<td><?=$i['product_name']?></td>
		<td><?=$i['warning_quantity']?></td>
		<td><?=$i['safe_quantity']?></td>
		<td><?=$i['stock_quantity']?></td>
		<td><?=$i['sold_quantity']?></td>
		<td><?=$i['budget_quantity']?></td>
		<td><?=sprintf('%.2f', $i['budget_price'])?></td>
		<td><?=$i['budget_provider_name']?></td>
		<td><input type="hidden" value="<?=$i['budget_quantity']?>" /><input type="text" size="4" class="actual_quantity" value="<?=$i['actual_quantity']?>" name="item[<?=$i['id']?>][actual_quantity]" <?if ($i['audit_flag']) echo "disabled='disabled'"?> /></td>
		<td><input type="hidden" value="<?=$i['budget_price']?>" /><input type="text" size="5" class="actual_price" value="<?=$i['actual_price'] ? sprintf('%.2f', $i['actual_price']) : ''?>" name="item[<?=$i['id']?>][actual_price]" <?if ($i['audit_flag']) echo "disabled='disabled'"?> /></td>
		<td>
			<input type="text" size="3" value="<?=$i['actual_provider_id']?>" disabled="disabled" class="actual_provider_id" />
			<input type="text" value="<?=$i['actual_provider_name']?>" class="ajax_provider" <?if ($i['audit_flag']) echo "disabled='disabled'"?> />
			<input type="hidden" value="<?=$i['actual_provider_id']?>" name="item[<?=$i['id']?>][actual_provider_id]" class="actual_provider_id" <?if ($i['audit_flag']) echo "disabled='disabled'"?>/>
		</td>
		<td><input type="text" name="item[<?=$i['id']?>][notes]" value="<?=$i['notes']?>" <?if ($i['audit_flag']) echo "disabled='disabled'"?> /></td>
	</tr>
	<?endforeach;?>
</table>
<input type="hidden" name="history" value="<?=$_SERVER['HTTP_REFERER']?>" />
<div align="right"><a id="note" >批量备注</a></div>
<div align="center"><input type="submit" class="button" id="add_save" value="保存" /><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></div>
</form>
<?php $this->_endblock(); ?>